/*******************************************************************************
 * Copyright (c) 2000, 2005 IBM Corporation and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *     IBM Corporation - initial API and implementation
 *******************************************************************************/
package org.skyeye.modeling.customerized.figures;

import org.eclipse.draw2d.ColorConstants;
import org.eclipse.draw2d.Graphics;
import org.eclipse.draw2d.Label;
import org.eclipse.draw2d.geometry.Dimension;
import org.eclipse.draw2d.geometry.Point;
import org.eclipse.draw2d.geometry.Rectangle;
import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Font;
import org.skyeye.modeling.Activator;
import org.skyeye.modeling.customerized.model.DVOutput;
import org.skyeye.modeling.customerized.model.SimpleInput;
import org.skyeye.modeling.customerized.model.SimpleOutput;

/**
 * @author danlee
 */
public class DVOutputFigure extends OutputFigure {
private static final Dimension SIZE = new Dimension(50, 50);
private Label nameLabel, numLabel;
private Font font = new Font(Activator.getActiveWorkbenchShell().getDisplay(),"courier", 10, 1); 
private DVOutput model ;
/**
 * Constructor for LiveOutputFigure.
 */
public DVOutputFigure(DVOutput model) {
	super();
	this.model = model;
	this.nameLabel = new Label();
	nameLabel.setText("VCC");
	nameLabel.setTextAlignment(Label.LEFT);
	nameLabel.setIconTextGap(5);
	this.add(nameLabel);
	
	this.numLabel = new Label();
	numLabel.setText(model.getCurrentValue()+"V");
	numLabel.setTextAlignment(Label.LEFT);
	numLabel.setFont(font);;
	this.add(numLabel);
}

/**
 * @see org.eclipse.draw2d.Figure#getPreferredSize(int, int)
 */
public Dimension getPreferredSize(int wHint, int hHint) {
	return SIZE;
}

/**
 * @see org.eclipse.draw2d.Figure#paintFigure(Graphics)
 */
protected void paintFigure(Graphics g) {
	test(g);
}

final int lineWidth = 1;
private void test(Graphics graphics){
	Rectangle bound = this.getBounds().getCopy();
	
	Point left = new Point(bound.x, bound.y+bound.height/2);
	Point right = new Point(bound.x+bound.width , bound.y+bound.height/2);
	Point center = new Point(bound.x+bound.width/2, bound.y+bound.height/2);
	Point bottom = new Point(bound.x+bound.width/2, bound.y+bound.height);
	
	graphics.setLineStyle(SWT.BOLD);
	graphics.setLineWidth(1);
	
	graphics.drawLine(left, right);
	graphics.drawLine(center, bottom);
    
    ((FixedConnectionAnchor)this.connectionAnchors.get(SimpleOutput.TERMINAL_OUT)).offsetH = bound.width/2;
    
    Rectangle tmp = new Rectangle(bound.x + 2,bound.y,bound.width,10);
	this.nameLabel.setBounds(tmp);
	
	Rectangle numRectangle = new Rectangle(center.x + 2,center.y+2,bound.width/2-2,bound.height/2-2);
	this.numLabel.setBounds(numRectangle);
	
	
}

}
